package com.company.quick56.web.util;

import java.io.IOException;
import java.io.OutputStream;

import javax.servlet.http.HttpServletResponse;

import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;

public class CommonUtil {
	private CommonUtil() {

	}

	public static boolean isBlank(String str) {
		return str == null || str.trim().length() == 0;
	}

	public static void generateExcel(HttpServletResponse response) {
		try {
			response.setHeader("Content-disposition", "attachment;filename=user_list.xls");
			response.setContentType("application/vnd.ms-excel");
			// response.setContentType("application/msexcel");

			OutputStream os = response.getOutputStream();
			WritableWorkbook book = Workbook.createWorkbook(os);

			String QUHAO = "11";
			String LOGINID = "11";
			String CALLTEL = "11";
			String OUT_TIME = "11";
			String SHICHANG = "11";
			String FEILV = "11";
			String FEIYONG = "11";
			String YEWU = "11";
			String CODE = "11";

			WritableSheet sheet = book.createSheet("固话话单", 0);

			sheet.addCell(new Label(0, 0, "区号"));
			sheet.addCell(new Label(1, 0, "主叫号码"));
			sheet.addCell(new Label(2, 0, "被叫号码"));
			sheet.addCell(new Label(3, 0, "起始时间"));
			sheet.addCell(new Label(4, 0, "时长(秒)"));
			sheet.addCell(new Label(5, 0, "费率(分)"));
			sheet.addCell(new Label(6, 0, "费用(分)"));
			sheet.addCell(new Label(7, 0, "说明"));
			sheet.addCell(new Label(8, 0, "计费代码"));

			for (int i = 0; i < 3; i++) {
				int t = i + 1;
				sheet.addCell(new Label(0, t, QUHAO));
				sheet.addCell(new Label(1, t, LOGINID));
				sheet.addCell(new Label(2, t, CALLTEL));
				sheet.addCell(new Label(3, t, OUT_TIME));
				sheet.addCell(new Label(4, t, SHICHANG));
				sheet.addCell(new Label(5, t, FEILV));
				sheet.addCell(new Label(6, t, FEIYONG));
				sheet.addCell(new Label(7, t, YEWU));
				sheet.addCell(new Label(8, t, CODE));
			}

			book.write();

			book.close();

			os.close();
		} catch (IOException e) {
			System.out.println("System hit IOException when generate excel");
		} catch (WriteException e) {
			System.out.println("System hit WriteException when generate excel");
		}

	}

}
